package com.csx.controller;

import com.csx.CheckDbDataTask;
import com.csx.Context;
import com.xxl.job.core.util.DateUtil;
import com.yh.csx.bsf.core.util.StringUtils;
import lombok.var;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Comparator;
import java.util.stream.Collectors;

@Controller
@RequestMapping("/")
public class TaskController {
	@GetMapping("/")
	@ResponseBody
	public String info(String old) {
		try {
			var str = new StringBuilder();
			var checkInfos = (StringUtils.isEmpty(old)?Context.CheckDbDataTask.getCheckInfos():Context.CheckDbDataTask.getLastCheckInfos())
					.stream()
					.sorted(Comparator.comparing(CheckDbDataTask.CheckInfo::getResult))
					.collect(Collectors.toList());
			for (var ckInfo : checkInfos) {
				str.append(ckInfo.toString().replace("[error]", "<span style='color:red'>")
						.replace("[/error]", "</span>")
						.replace("[success]", "<span style='color:green'>")
						.replace("[/success]", "</span>")
						.replace("[warn]", "<span style='color:orange'>")
						.replace("[/warn]", "</span>")
						.replace("\r\n", "<br/>"));
			}

			return "<b><a href='/?old=1'>旧报表</a></b><br/>" + str.toString();
		}catch (Exception e){
			return e.getMessage();
		}

	}
	
}
